//
//  ChatNavView.m
//  IMMantisSDK_Example
//
//  Created by 陈志亮 on 2021/4/2.
//  Copyright © 2021 chenzhiliang. All rights reserved.
//

#import "ChatNavView.h"
#import "CommonHeader.h"
@interface ChatNavView()
@property(nonatomic,strong)UIImageView*avaterImgView;
@end


@implementation ChatNavView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setUpView];
    }

    return  self;
    
}

-(void)setUpView{
    CGFloat spceMargin =adaptWidth750(20);
    UIImageView*avaterImgView = [UIImageView new];
    self.avaterImgView=avaterImgView;
    UIImage*avaterImg =[UIImage imageNamed:@"chat_visitor_avater"];
    avaterImgView.image=avaterImg;
    [self addSubview:avaterImgView];
    CGFloat imgWidth =adaptWidth750(60);
    [avaterImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(spceMargin);
        make.centerY.equalTo(self).offset(isIMIphoneX?adaptWidth750(18):0);
        make.width.height.mas_equalTo(imgWidth);
    }];
    
    ViewRadius(avaterImgView, imgWidth/2);
    
    

    UILabel*backLabel = [UILabel new];
    self.backLabel=backLabel;
    backLabel.text=@"您正在与咨询师沟通";
    backLabel.textColor = [UIColor jk_colorWithHexString:@"#333333"];
    backLabel.font = KIMFontRegularSize(14);
    backLabel.numberOfLines=1;
    [self addSubview:backLabel];
    
    [backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avaterImgView.mas_right).offset(adaptWidth750(20));
        make.centerY.equalTo(avaterImgView);
        make.width.mas_equalTo(adaptWidth750(400));
    }];
    
    
    UIView*lineView = [UIView new];
    lineView.backgroundColor = KLineColor;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self);
        make.height.mas_equalTo(@1);
    }];
    
    
    UIImageView*closeImgView = [UIImageView new];
    closeImgView.image = [UIImage imageNamed:@"base_back"];
    [self addSubview:closeImgView];

    [closeImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backLabel);
        make.right.mas_equalTo(-spceMargin);
    }];
    

    UIButton*clickBtn = [UIButton new];
    self.backBtn=clickBtn;
    clickBtn.backgroundColor = [UIColor clearColor];
    [self addSubview:clickBtn];
    [clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self);
        make.width.mas_equalTo(adaptWidth750(200));
    }];
    
    
}


-(void)reloadNavView:(MatinsIMinitModel*)model{
    if (model.mbTitleColor.length>0) {
        self.backgroundColor = [UIColor jk_colorWithHexString:model.mbTitleColor];
        self.backLabel.textColor = [UIColor jk_colorWithHexString:model.mbTitleTxtColor];
        
    }
    self.backLabel.text=model.mbTitleTxt;
    
    if (model.mbAgentIcon.length>0) {
        [self.avaterImgView setImageWithURL:[NSURL URLWithString:model.mbAgentIcon] placeholder:[UIImage imageNamed:@"chat_visitor_avater"]];
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
